1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.google.common.base;
18
19 import com.google.caliper.Benchmark;
20 import com.google.common.base.Objects;
21
22
23
24
25
26
27 public class ObjectsBenchmark {
28
29 private static final Integer I0 = -45;
30 private static final Integer I1 = -1;
31 private static final Integer I2 = 3;
32 private static final String S0 = "3";
33 private static final String S1 = "Ninety five";
34 private static final String S2 = "44 one million";
35 private static final String S3 = "Lowly laundry lefties";
36 private static final String S4 = "89273487U#*&#";
37 private static final Double D0 = 9.234d;
38 private static final Double D1 = -1.2e55;
39
40 @Benchmark int hashString_2(int reps) {
41 int dummy = 0;
42 for (int i = 0; i < reps; i++) {
43 dummy += Objects.hashCode(S0, S1);
44 }
45 return dummy;
46 }
47
48 @Benchmark int hashString_3(int reps) {
49 int dummy = 0;
50 for (int i = 0; i < reps; i++) {
51 dummy += Objects.hashCode(S0, S1, S2);
52 }
53 return dummy;
54 }
55
56 @Benchmark int hashString_4(int reps) {
57 int dummy = 0;
58 for (int i = 0; i < reps; i++) {
59 dummy += Objects.hashCode(S0, S1, S2, S3);
60 }
61 return dummy;
62 }
63
64 @Benchmark int hashString_5(int reps) {
65 int dummy = 0;
66 for (int i = 0; i < reps; i++) {
67 dummy += Objects.hashCode(S0, S1, S2, S3, S4);
68 }
69 return dummy;
70 }
71
72 @Benchmark int hashMixed_5(int reps) {
73 int dummy = 0;
74 for (int i = 0; i < reps; i++) {
75 dummy += Objects.hashCode(I2, S1, D1, S2, I0);
76 dummy += Objects.hashCode(D0, I1, S3, I2, S0);
77 }
78 return dummy;
79 }
80 }